package com.hardson.toolkit.util;

/**
 * 操作系统类： 获取System.getProperty("os.name")对应的操作系统
 *
 * @author isea533
 */
public class OSInfo {

    public static final String osName = System.getProperty("os.name").toLowerCase();
    public static final String osArch = System.getProperty("os.arch").toLowerCase();

    public static boolean isLinux() {
        return osName.contains("linux");
    }

    public static boolean isMacOS() {
        return osName.contains("mac") && osName.indexOf("os") > 0 && !osName.contains("x");
    }

    public static boolean isMacOSX() {
        return osName.contains("mac") && osName.indexOf("os") > 0 && osName.indexOf("x") > 0;
    }

    public static boolean isWindows() {
        return osName.contains("windows");
    }

    public static boolean isOS2() {
        return osName.contains("os/2");
    }

    public static boolean isSolaris() {
        return osName.contains("solaris");
    }

    public static boolean isSunOS() {
        return osName.contains("sunos");
    }

    public static boolean isMPEiX() {
        return osName.contains("mpe/ix");
    }

    public static boolean isHPUX() {
        return osName.contains("hp-ux");
    }

    public static boolean isAix() {
        return osName.contains("aix");
    }

    public static boolean isOS390() {
        return osName.contains("os/390");
    }

    public static boolean isFreeBSD() {
        return osName.contains("freebsd");
    }

    public static boolean isIrix() {
        return osName.contains("irix");
    }

    public static boolean isDigitalUnix() {
        return osName.contains("digital") && osName.indexOf("unix") > 0;
    }

    public static boolean isNetWare() {
        return osName.contains("netware");
    }

    public static boolean isOSF1() {
        return osName.contains("osf1");
    }

    public static boolean isOpenVMS() {
        return osName.contains("openvms");
    }

    /**
     * 获取操作系统名字
     *
     * @return 操作系统名
     */
    public static EPlatform getOSname() {
        if (isWindows()) {
            return EPlatform.Windows;
        }
        if (isLinux()) {
            return EPlatform.Linux;
        }
        if (isAix()) {
            return EPlatform.AIX;
        }
        if (isMacOS()) {
            return EPlatform.Mac_OS;
        }
        if (isMacOSX()) {
            return EPlatform.Mac_OS_X;
        }
        if (isDigitalUnix()) {
            return EPlatform.Digital_Unix;
        }
        if (isFreeBSD()) {
            return EPlatform.FreeBSD;
        }
        if (isHPUX()) {
            return EPlatform.HP_UX;
        }
        if (isIrix()) {
            return EPlatform.Irix;
        }
        if (isMPEiX()) {
            return EPlatform.MPEiX;
        }
        if (isNetWare()) {
            return EPlatform.NetWare_411;
        }
        if (isOpenVMS()) {
            return EPlatform.OpenVMS;
        }
        if (isOS2()) {
            return EPlatform.OS2;
        }
        if (isOS390()) {
            return EPlatform.OS390;
        }
        if (isOSF1()) {
            return EPlatform.OSF1;
        }
        if (isSolaris()) {
            return EPlatform.Solaris;
        }
        if (isSunOS()) {
            return EPlatform.SunOS;
        }
        return EPlatform.Others;
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        System.out.println(OSInfo.getOSname());
    }

}
